package marcis.jarina.export;

import marcis.jarina.directory.repository.JarVersion;
import marcis.jarina.hibernate.entities.Archive;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


public class TextFileExport {

    public static List<Archive> fakeData() {
        List<Archive> hundred = new ArrayList<Archive>();
        Archive a1 = new Archive();
        a1.setFilePath("fileName");
        a1.setArtifactId("artifactId");
        a1.setGroupId("groupId");
        a1.setId(11);
        a1.setJarVersion(new JarVersion("1.1.1"));
        hundred.add(a1);
        return hundred;
    }

    public static void main(String[] args) throws IOException {
        /*
        HibernateDAO<Archive> archiveHibernateDAO = new HibernateDAO<Archive>();
        List<Archive> hundred = archiveHibernateDAO.getPagedList(Archive.class, 0, 100);
        */
        //writeListObject(hundred);


        writeListText(fakeData());
    }

    private static void writeListText(List<Archive> hundred) throws IOException {
        FileWriter bos = new FileWriter(new File("hundred.txt"));
        StringBuilder stringBuilder = new StringBuilder();
        for (Archive archive : hundred) {
            stringBuilder.append(archive.toString());
        }
        bos.append(stringBuilder.toString());
        bos.close();
    }

    public static <T> void writeListObject(List<T> list) throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(
                new FileOutputStream(new File("hundred.ser"))));
        oos.writeObject(list);
        oos.close();
    }

    public static void parseArchives() throws IOException {
        FileReader reader = new FileReader(new File("hundred.txt"));

        char[] znaky = new char[8192];
        while (reader.read(znaky) != -1) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(znaky);
        }


    }


}
